App.require(["strui", "page", "popUp", "component", "widget", "behavior", "scene"],
    function (strui, page, popUp, component, widget, behavior, scene) {
        var app = null;
        var search = location.search;
        if (search && search.slice(1) === "viewer") {
            app = App.create("review", "static", "viewer", App.version);
        }
        else {
            app = App.create("visualization", "static", "index", App.version);
        }

        app.setPageConfig(page);
        app.setComponentConfig(component);
        app.setPopUpConfig(popUp);

        Page.prototype.showCommonDialog = function (pagename, config, isBack) {
            config = config || {};
            config.pagename = pagename;
            config.currentpage = config.currentPage || this.name;
            config.btns = config.btns || [];
            config.addClass = config.addClass || "";
            this.showPopUp("dialog", config, isBack);
        };

        var len = 4;
        function ready() {
            if (--len === 0) app.initialize(document.body);
        }

        app.wm = new App.WidgetManager(widget, ready);
        app.wbm = new App.WidgetBehaviorManager(behavior, ready);
        app.sm = new App.SceneManager(scene, ready);

        App.defineWidget = function (name, option) {
            return app.wm.defineWidget(name, option);
        }

        App.defineWidgetBehavior = function (name, option) {
            return app.wbm.defineWidgetBehavior(name, option);
        }

        App.defineScene = function (name, option) {
            return app.sm.defineScene(name, option);
        }

        strui.init(app, ready)
    });